from fastapi import APIRouter, Body, Query, Request
from api.service.eshop_assistant_service import EShopAssistantService
from domain.page import Page
from domain.run_info import RunInfo
from domain.spider_params import SpiderParams
from domain.unsatisfited_pic import UnSatisfiedPic

from domain.user import User

router = APIRouter()
service = EShopAssistantService()


@router.post("/api/update/spider_info", tags=["电商运营助手接口"], description="更新爬取店铺以及关键字信息")
def update_spider_info(spider_info : SpiderParams = Body(..., description="爬取信息")):
    return service.update_spider_info(spider_info)

@router.get("/api/get_spider_info", tags=["电商运营助手接口"], description="获取店铺以及关键字信息")
def get_spider_info():
    return service.get_spider_info()

@router.post("/api/run", tags=["电商运营助手接口"], description="运行")
def run(run_info : RunInfo = Body(default=..., description="运行信息")):
    return service.run(run_info)

@router.get("/api/get_task_info", tags=["电商运营助手接口"], description="获取任务运行详情")
def get_task_info(task_id : str = Query(..., description="任务id")):
    return service.get_task_info(task_id)

@router.post("/api/get_task_list")
def get_task_list(page_info:Page = Body(...,description="分页信息")):
    return service.get_task_list(page_info)

@router.get("/api/get_task_result", tags=["电商运营助手接口"], description="获取任务运行结果")
def get_task_info(task_id : str = Query(..., description="任务id")):
    return service.get_task_result(task_id)

@router.post("/api/unsatisfied", tags=["电商运营助手接口"], description="不满意")
def unsatisfied(unsatisfied_pic:UnSatisfiedPic = Body(default=..., description="不满意的图片")):
    return service.unsatisfied(unsatisfied_pic)

@router.post("/api/login", tags=["电商运营助手接口"], description="登录")
def login(user : User = Body(default=..., description="用户信息")):
    return service.login(user)

@router.get("/api/getUserInfo", tags=["电商运营助手接口"], description="获取用户信息")
def get_user_info(user_id : str = Query(..., description="用户id")):
    return service.get_user_info(user_id)